package com.ruoyi.hcmain.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.hcmain.domain.HcStock;
import com.ruoyi.hcmain.service.IHcStockService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 仓库信息Controller
 * 
 * @author ruoyi
 * @date 2023-08-10
 */
@RestController
@RequestMapping("/system/stock")
public class HcStockController extends BaseController
{
    @Autowired
    private IHcStockService hcStockService;

    /**
     * 查询仓库信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:stock:list')")
    @GetMapping("/list")
    public AjaxResult list(HcStock hcStock)
    {
        List<HcStock> list = hcStockService.selectHcStockList(hcStock);
        return success(list);
    }

    /**
     * 导出仓库信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:stock:export')")
    @Log(title = "仓库信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HcStock hcStock)
    {
        List<HcStock> list = hcStockService.selectHcStockList(hcStock);
        ExcelUtil<HcStock> util = new ExcelUtil<HcStock>(HcStock.class);
        util.exportExcel(response, list, "仓库信息数据");
    }

    /**
     * 获取仓库信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:stock:query')")
    @GetMapping(value = "/{stockId}")
    public AjaxResult getInfo(@PathVariable("stockId") Long stockId)
    {
        return success(hcStockService.selectHcStockByStockId(stockId));
    }

    /**
     * 新增仓库信息
     */
    @PreAuthorize("@ss.hasPermi('system:stock:add')")
    @Log(title = "仓库信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HcStock hcStock)
    {
        return toAjax(hcStockService.insertHcStock(hcStock));
    }

    /**
     * 修改仓库信息
     */
    @PreAuthorize("@ss.hasPermi('system:stock:edit')")
    @Log(title = "仓库信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HcStock hcStock)
    {
        return toAjax(hcStockService.updateHcStock(hcStock));
    }

    /**
     * 删除仓库信息
     */
    @PreAuthorize("@ss.hasPermi('system:stock:remove')")
    @Log(title = "仓库信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{stockIds}")
    public AjaxResult remove(@PathVariable Long[] stockIds)
    {
        return toAjax(hcStockService.deleteHcStockByStockIds(stockIds));
    }
}
